package com.appwoo.txtws.service;

import android.content.Context;
import com.appwoo.android.exception.NotFoundNetWorkException;
import com.appwoo.android.exception.TimeOutException;
import com.appwoo.android.util.PullIO;
import com.appwoo.txtws.bean.BookBean;
import com.appwoo.txtws.bean.BookMenuBean;
import com.appwoo.txtws.bean.BookModuleBean;
import com.appwoo.txtws.bean.BookReaderQuestionWebEntity;
import com.appwoo.txtws.component.Logger;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

public class BookService
{
  private Context context;

  public BookService(Context paramContext)
  {
    this.context = paramContext;
  }

  private int toInteger(String paramString, int paramInt)
  {
    try
    {
      int i = Integer.parseInt(paramString);
      return i;
    }
    catch (NumberFormatException localNumberFormatException)
    {
      localNumberFormatException.printStackTrace();
    }
    return paramInt;
  }

  public ArrayList<BookBean> getBookBeanList(String paramString1, String paramString2, int paramInt1, String paramString3, String paramString4, int paramInt2, int paramInt3)
  {
    ArrayList localArrayList = new ArrayList();
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<?xml version=\"1.0\" encoding=\"utf-8\"?><MSG><HEAD><SNDR>").append(paramString1).append("</SNDR><TYPE>RQBooks</TYPE></HEAD><BODY>");
    if ((paramString2 != null) && (!"".equals(paramString2)))
      localStringBuilder.append("<Name>").append(paramString2).append("</Name>");
    localStringBuilder.append("<Type>").append(paramInt1).append("</Type>");
    localStringBuilder.append("<Grade>").append(paramString3).append("</Grade>");
    if ((paramString4 != null) && (!"".equals(paramString4)) && (!"全部".equals(paramString4)))
      localStringBuilder.append("<Subject>").append(paramString4).append("</Subject>");
    if (paramInt3 > 20)
      paramInt3 = 20;
    localStringBuilder.append("<PageIndex>").append(paramInt2).append("</PageIndex><PageSize>").append(paramInt3).append("</PageSize></BODY></MSG>");
    Logger.e("REQUEST BOOKBEAN LIST TEXT:", localStringBuilder.toString());
    MsgService localMsgService = new MsgService();
    int i;
    try
    {
      String str1 = localMsgService.sendMessage(paramString1, localStringBuilder.toString(), this.context);
      Logger.e("RESPONSE BOOKBEAN LIST TEXT:", str1);
      if ((str1 == null) || ("".equals(str1)))
        break label506;
      localXmlPullParser = PullIO.getPullByString(str1);
      i = localXmlPullParser.getEventType();
      localBookBean = null;
      break label500;
      while (true)
      {
        i = localXmlPullParser.next();
        break label500;
        if ("List".equalsIgnoreCase(localXmlPullParser.getName()))
        {
          localBookBean = new BookBean();
        }
        else
        {
          if (!"Name".equalsIgnoreCase(localXmlPullParser.getName()))
            break;
          localBookBean.setName(localXmlPullParser.nextText());
        }
      }
    }
    catch (IOException localIOException)
    {
      while (true)
      {
        localIOException.printStackTrace();
        return localArrayList;
        if (!"Size".equalsIgnoreCase(localXmlPullParser.getName()))
          break;
        localBookBean.setSize(toInteger(localXmlPullParser.nextText(), 0));
      }
    }
    catch (XmlPullParserException localXmlPullParserException)
    {
      while (true)
      {
        localXmlPullParserException.printStackTrace();
        return localArrayList;
        if ("Path".equalsIgnoreCase(localXmlPullParser.getName()))
        {
          String str2 = localXmlPullParser.nextText();
          if (str2 != null)
            str2 = str2.replace("\\", "/");
          localBookBean.setDownloadPath(str2 + "/");
        }
      }
    }
    catch (TimeOutException localTimeOutException)
    {
      while (true)
      {
        XmlPullParser localXmlPullParser;
        BookBean localBookBean;
        localTimeOutException.printStackTrace();
        return localArrayList;
        if ("List".equalsIgnoreCase(localXmlPullParser.getName()))
          localArrayList.add(localBookBean);
      }
    }
    catch (NotFoundNetWorkException localNotFoundNetWorkException)
    {
      localNotFoundNetWorkException.printStackTrace();
      return localArrayList;
    }
    label500: if (i == 1)
      label506: return localArrayList;
    switch (i)
    {
    case 0:
    case 1:
    default:
    case 2:
    case 3:
    }
  }

  public ArrayList<String> getBookImageBeanList(String paramString1, String paramString2)
  {
    ArrayList localArrayList = new ArrayList();
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<?xml version=\"1.0\" encoding=\"utf-8\"?><MSG><HEAD><SNDR>").append(paramString1).append("</SNDR><TYPE>RQBookImgs</TYPE></HEAD><BODY>");
    localStringBuilder.append("<Name>").append(paramString2).append("</Name>");
    localStringBuilder.append("</BODY></MSG>");
    MsgService localMsgService = new MsgService();
    int i;
    try
    {
      String str1 = localMsgService.sendMessage(paramString1, localStringBuilder.toString(), this.context);
      FileOutputStream localFileOutputStream = new FileOutputStream("/sdcard/tylw/response.txt");
      localFileOutputStream.write(str1.getBytes("UTF-8"));
      localFileOutputStream.flush();
      localFileOutputStream.close();
      Logger.e("RESPONSE BOOKBEAN LIST TEXT:", str1);
      if ((str1 == null) || ("".equals(str1)))
        break label449;
      XmlPullParser localXmlPullParser = PullIO.getPullByString(str1);
      i = localXmlPullParser.getEventType();
      String str2 = "";
      break label443;
      while (true)
      {
        i = localXmlPullParser.next();
        break;
        "Url".equalsIgnoreCase(localXmlPullParser.getName());
        if ("List".equalsIgnoreCase(localXmlPullParser.getName()))
        {
          str2 = "";
        }
        else if ("Path".equalsIgnoreCase(localXmlPullParser.getName()))
        {
          str2 = localXmlPullParser.nextText();
          if (str2 != null)
          {
            str2 = str2.replace("\\", "/");
            if (!str2.endsWith("/"))
              str2 = str2 + "/";
          }
        }
        else if ("Imgs".equalsIgnoreCase(localXmlPullParser.getName()))
        {
          String str3 = localXmlPullParser.nextText();
          if ((str3 != null) && (!"".equals(str3)))
          {
            for (String str4 : str3.split(";"))
              localArrayList.add("" + str2 + str4);
            continue;
            "List".equalsIgnoreCase(localXmlPullParser.getName());
          }
        }
      }
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
      return localArrayList;
    }
    catch (XmlPullParserException localXmlPullParserException)
    {
      localXmlPullParserException.printStackTrace();
      return localArrayList;
    }
    catch (TimeOutException localTimeOutException)
    {
      localTimeOutException.printStackTrace();
      return localArrayList;
    }
    catch (NotFoundNetWorkException localNotFoundNetWorkException)
    {
      localNotFoundNetWorkException.printStackTrace();
      return localArrayList;
    }
    label443: if (i == 1)
      label449: return localArrayList;
    switch (i)
    {
    case 0:
    case 1:
    default:
    case 2:
    case 3:
    }
  }

  public BookReaderQuestionWebEntity getBookUnitList(String paramString1, String paramString2)
  {
    BookReaderQuestionWebEntity localBookReaderQuestionWebEntity = new BookReaderQuestionWebEntity();
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<?xml version=\"1.0\" encoding=\"utf-8\"?><MSG><HEAD><SNDR>").append(paramString1).append("</SNDR><TYPE>RQPrew</TYPE></HEAD><BODY>").append("<Name>").append(paramString2).append("</Name></BODY></MSG>");
    Logger.e("REQUEST BOOKUNIT TEXT:", localStringBuilder.toString());
    MsgService localMsgService = new MsgService();
    while (true)
    {
      XmlPullParser localXmlPullParser;
      int i;
      ArrayList localArrayList1;
      BookMenuBean localBookMenuBean1;
      int j;
      int k;
      try
      {
        String str1 = localMsgService.sendMessage(paramString1, localStringBuilder.toString(), this.context);
        Logger.e("RESPONSE BOOKBEAN LIST TEXT:", str1);
        if ((str1 == null) || ("".equals(str1)))
          break label572;
        localXmlPullParser = PullIO.getPullByString(str1);
        i = localXmlPullParser.getEventType();
        localArrayList1 = new ArrayList();
        localBookMenuBean1 = null;
        localArrayList2 = null;
        break label566;
        i = localXmlPullParser.next();
        break label566;
        if ("Units".equalsIgnoreCase(localXmlPullParser.getName()))
        {
          localBookMenuBean1 = new BookMenuBean();
          localArrayList2 = new ArrayList();
          localBookMenuBean1.setLevel(0);
          localBookMenuBean1.setMenus(localArrayList2);
          continue;
        }
      }
      catch (IOException localIOException)
      {
        localIOException.printStackTrace();
        return localBookReaderQuestionWebEntity;
        if ("Unit".equalsIgnoreCase(localXmlPullParser.getName()))
        {
          localBookMenuBean1.setTitle(localXmlPullParser.nextText());
          continue;
        }
      }
      catch (XmlPullParserException localXmlPullParserException)
      {
        ArrayList localArrayList2;
        localXmlPullParserException.printStackTrace();
        return localBookReaderQuestionWebEntity;
        if ("Course".equalsIgnoreCase(localXmlPullParser.getName()))
        {
          String str4 = localXmlPullParser.nextText();
          if (str4 == null)
            continue;
          String[] arrayOfString2 = str4.split(";");
          int m = arrayOfString2.length;
          int n = 0;
          if (n >= m)
            continue;
          String str5 = arrayOfString2[n];
          BookMenuBean localBookMenuBean2 = new BookMenuBean();
          localBookMenuBean2.setTitle(str5);
          localBookMenuBean2.setLevel(1);
          localBookMenuBean2.setPath(null);
          localArrayList2.add(localBookMenuBean2);
          n++;
          continue;
        }
        if ("Type".equals(localXmlPullParser.getName()))
        {
          String str2 = localXmlPullParser.nextText();
          localArrayList3 = new ArrayList();
          if (str2 != null)
          {
            arrayOfString1 = str2.split(";");
            j = arrayOfString1.length;
            k = 0;
            break label608;
          }
          localBookReaderQuestionWebEntity.setBookModules(localArrayList3);
          continue;
        }
      }
      catch (TimeOutException localTimeOutException)
      {
        ArrayList localArrayList3;
        String[] arrayOfString1;
        localTimeOutException.printStackTrace();
        return localBookReaderQuestionWebEntity;
        String str3 = arrayOfString1[k];
        BookModuleBean localBookModuleBean = new BookModuleBean();
        localBookModuleBean.setName(str3);
        localBookModuleBean.setPath(null);
        localBookModuleBean.setType(null);
        localArrayList3.add(localBookModuleBean);
        k++;
        break label608;
        if (!"Content".equals(localXmlPullParser.getName()))
          continue;
        localBookReaderQuestionWebEntity.setContent(localXmlPullParser.nextText());
        continue;
      }
      catch (NotFoundNetWorkException localNotFoundNetWorkException)
      {
        localNotFoundNetWorkException.printStackTrace();
        return localBookReaderQuestionWebEntity;
      }
      if ("Units".equalsIgnoreCase(localXmlPullParser.getName()))
      {
        localArrayList1.add(localBookMenuBean1);
      }
      else if ("BODY".equalsIgnoreCase(localXmlPullParser.getName()))
      {
        localBookReaderQuestionWebEntity.setBookMenus(localArrayList1);
        continue;
        label566: if (i == 1)
          label572: return localBookReaderQuestionWebEntity;
        switch (i)
        {
        case 0:
        case 1:
        default:
        case 2:
        case 3:
        }
        label608: if (k < j);
      }
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.service.BookService
 * JD-Core Version:    0.6.2
 */